package com.xx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xx.entity.Employees;
import com.xx.entity.EmployeesRegister;
import com.xx.mapper.EmployeesMapper;
import com.xx.service.EmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class EmployeesServiceImpl implements EmployeesService{

    @Autowired
    EmployeesMapper employeesMapper;
    @Override
    public PageInfo<Employees> selectAllByPage(Employees employees, Integer pageNum) {
        PageHelper.startPage(pageNum,5);
        List<Employees> employeesList = employeesMapper.selectAllByPage(employees);
        PageInfo<Employees> pageInfo  = new PageInfo<>(employeesList);
        return pageInfo;
    }

    @Override
    public Employees selectByEmployeeId(Integer employeeId) {
        return employeesMapper.selectByEmployeeId(employeeId);
    }

    @Override
    public int insertSelective(Employees employees) {
        return employeesMapper.insertSelective(employees);
    }

    @Override
    public int updateByEmployeeId(Employees updated, Integer employeeId) {
        return employeesMapper.updateByEmployeeId(updated, employeeId);
    }

    @Override
    public int deleteByEmployeeId(Integer employeeId) {
        return employeesMapper.deleteByEmployeeId(employeeId);
    }

    @Override
    public Employees selectByLoginName(String loginName,String password) {
        Employees employees = employeesMapper.selectByLoginName(loginName);
        if (employees.getPassword().equals(password)){
            return employees;
        }
        return null;
    }

    @Override
    public int registerEmployees(EmployeesRegister employeesRegister) {
        return employeesMapper.registerEmployees(employeesRegister);
    }
}




